
package com.csun.cmny.provider.service.impl;


import com.csun.cmny.base.constant.AliyunSmsConstants;
import com.csun.cmny.provider.model.dto.sms.SmsMessage;
import com.csun.cmny.provider.service.SmsService;
import com.csun.cmny.security.core.validate.code.sms.SmsCodeSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 默认的短信验证码发送器
 *
 * @author paascloud.net @gmail.com
 */
@Slf4j
@Service
public class CmnySmsCodeSender implements SmsCodeSender {

	@Resource
	private SmsService smsService;

	@Override
	public void send(String mobile, String code, String ip, String busType) {
		log.info("ip地址 ==》[{}] 向手机 ==》[{}] 发送短信验证码 ==> [{}] 短信类型 ==》[{}]",
				ip, mobile, code, busType);
		SmsMessage smsMessage = new SmsMessage();
		smsMessage.setMobileNo(mobile);
		smsMessage.setSmsCode(code);
		AliyunSmsConstants.SmsTemplateEnum templateEnum = AliyunSmsConstants.SmsTemplateEnum.getBusType(busType);
		if (templateEnum == null) {
			templateEnum = AliyunSmsConstants.SmsTemplateEnum.DEFAULT_CHECK_AUTH_CODE;
		}
		smsMessage.setSmsTemplateCode(templateEnum.getTemplateCode());
		smsService.sendSmsCode(smsMessage, ip);
	}

}
